﻿// -------------------------------------------------------------------------
//    @FileName         :    CNVOtherEnterView.h
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-28
//    @Email			:    445267987@qq.com
//    @Module           :    CNVOtherEnterView
//    @Desc             :
//
// -------------------------------------------------------------------------

#pragma once

#include "NFCityPlayerViewExt.h"
#include "NFCityWorldObjectFunc.h"
#include "proto_cs.pb.h"
#include "NFComm/NFShmStl/NFShmHashMapWithList.h"
#include "NFComm/NFShmStl/NFShmVector.h"

const int MAX_PLAYER_IN_MAP_GRID = 500;

typedef NFShmHashMapWithList<uint64_t, int, MAX_PLAYER_IN_MAP_GRID> NFCityViewPlayerList;

class NFCityPlayer;
class NFCityNeighborGrid;

class NFNVOtherEnterView : public NFICityWorldObjectFunc
{
public:
    NFNVOtherEnterView(NFCityPlayer* pPlayer, NFCityNeighborGrid* pNeighborGrids);
    ~NFNVOtherEnterView() override;
    int DoFunc(NFCityWorldObject* pWorldObject) override;
    bool IsBreakIterate() override { return false; }
    int Send();

protected:
    virtual int AddEnterPlayer(NFCityPlayer* pPlayer, int iScore);
    bool IsPlayerTeamLeaderInView(NFCityPlayer* pPlayer);
    int EnterView(NFCityWorldObject* pWorldObject, int iScore);

protected:
    proto_ff::Proto_CSRsp m_oCSRsp;
    NFCityPlayer* m_pPlayer;
    NFCityNeighborGrid* m_pNeighborGrids;
    NFCityViewPlayerList m_stViewPlayerList;
    NFShmVector<NFCityPlayer*, MAX_VIEW_PLAYER_NUM> m_apViewPlayer;

protected:
    int m_iCurGridIdx;
    int m_iGridViewNum;

protected:
    int m_iEnterViewCnt;
    bool m_bIsBreakIterate;
    bool m_bInTeam;
};

class NFNVEnterViewOther : public NFICityWorldObjectFunc
{
public:
    NFNVEnterViewOther(NFCityPlayer* pPlayer);

    ~NFNVEnterViewOther() override
    {
    }

    int DoFunc(NFCityWorldObject* pWorldObject) override;

    virtual bool IsBreakIterate() { return m_bIsBreakIterate; }

private:
    int EnterViewOther(NFCityPlayer* pPlayer, int iScore);

    NFCityPlayer* m_pPlayer;
    proto_ff::Proto_CSRsp m_oCSRsp;

    bool m_bIsAction;
    proto_ff::Proto_CSRsp m_oCSActionRsp;

    bool m_bIsBreakIterate;
};

class NFNVOtherLeaveView : public NFICityWorldObjectFunc
{
public:
    NFNVOtherLeaveView(NFCityPlayer* pPlayer) : m_iLeaveViewCnt(0), m_pPlayer(pPlayer)
    {
        m_oCSRsp.mutable_map_leave_view_ntf()->set_reason(proto_ff::LEAVE_VIEW_OUT);
    }

    ~NFNVOtherLeaveView() override
    {
    }

    int DoFunc(NFCityWorldObject* pWorldObject) override;
    int Send();

private:
    int m_iLeaveViewCnt;
    NFCityPlayer* m_pPlayer;
    proto_ff::Proto_CSRsp m_oCSRsp;
};


class NFNVLeaveViewOther : public NFICityWorldObjectFunc
{
public:
    NFNVLeaveViewOther(NFCityPlayer* pPlayer);

    ~NFNVLeaveViewOther() override
    {
    }

    int DoFunc(NFCityWorldObject* pWorldObject) override;

private:
    int m_iLeaveViewCnt;
    NFCityPlayer* m_pPlayer;
    proto_ff::Proto_CSRsp m_oCSRsp;
};
